$(function(){
	
	/** 上传控件初始化 */
	fileUpload({
		positionId:'funds_fileupload',
		type: 'edit',
		initType:'ajax',
		ajaxUrl:'attachment/attachments.shtml',
		ajaxData:{bizId : $('#projectIndexId').val(), attaType:'projectIndex_funds'},
		atta_name : 'attaFunds',
		upload_table : 'funds_upload_table'
	});
	fileUpload({
		positionId:'result_fileupload',
		type: 'edit',
		initType:'ajax',
		ajaxUrl:'attachment/attachments.shtml',
		ajaxData:{bizId : $('#projectIndexId').val(), attaType:'projectIndex_result'},
		atta_name : 'attaResult',
		upload_table : 'result_upload_table'
	});
	
	/** 初始化指标 */
	$('#id').combotree({
		url : 'projectIndex/projectIndexs.shtml',
		onLoadSuccess : function (node, data) {
			 var t = $(this);
	  		 if(data){
			     $(data).each(function(index,d){
					if(this.state == 'closed'){
					    t.tree('expandAll');
					}
			     });
			}
		},
		required : true,
		tipPosition : 'bottom',
		missingMessage : '请选择所属指标'
	});
	$('#pId_clear_btn').click(function(){
		$('#id').combotree('clear');
	});
	
	
	/** 保存 */
	$('#btnSave').click(function(){
		var _projectIndexId = $('#id').combotree('getValue');
		if (null == _projectIndexId || '' == _projectIndexId) {
			$.messager.alert('提醒', '请选择所属指标','wanring');
			return false;
		}
		
		var valid = $('#form').form('validate');
		if(valid) {
			$("body").mask();
			$('#form').ajaxSubmit({
				url : 'projectIndex/saveAttas.shtml',
				success : function(data) {
					$("body").unmask();
					if (!data.success) {
						$.messager.alert('提醒', '上传失败','info');
					} else {
						$.messager.alert('提醒', '上传成功','info', function(){
							//TODO:
							parent.closeEasyUiWindow('win');
							parent.reSearch();
						});
					}
				}
			});
		}
	});
	
	/** 取消 */
	$('#btnCancel').click(function(){
		$('#form').form('clear');
		parent.closeEasyUiWindow('win');
	});
	
});